package bdqn.t09.controller;

import bdqn.t09.pojo.AsUser;
import bdqn.t09.service.AsUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UpdateController {
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public Object verifyPassword(String password, HttpSession session) {
        AsUser user = (AsUser) session.getAttribute("loginUser");
        if (user.getUserpassword().equals(password)) {
            return "true";
        }
        return "false";
    }

    @Resource
    private AsUserService asUserService;

    @ResponseBody
    @RequestMapping(value = "updatepassword", method = RequestMethod.POST)
    public Object updatePassword(String password, String userpassword, HttpSession session) {
        AsUser user = (AsUser) session.getAttribute("loginUser");
        if (user.getUserpassword().equals(password)) {
            AsUser asUser = new AsUser();
            asUser.setId(user.getId());
            asUser.setUserpassword(userpassword);
            int i = asUserService.updatePassword(asUser);
            return i;
        }
        return -1;
    }
}
